﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Surpass.Model.Dto.ResponseDto.ResponseModel.ResultModel;
using Surpass.Repository.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Surpass.Repository.IRepository;
using Microsoft.AspNetCore.Cors;
using Surpass.Model.Dto.ResponseDto.ResponseModel.PermissionModel;

namespace Surpass.Admin.Controllers
{

    [Route("api/[controller]")]
    [ApiController]
    public class RoleController : ControllerBase
    {
        private readonly ISysRoleRepository _sysRoleRepository;
        public RoleController(ISysRoleRepository sysRoleRepository)
        {
            _sysRoleRepository = sysRoleRepository;
        }
        /// <summary>
        /// 获取所有角色
        /// </summary>
        /// <returns></returns>
        [HttpGet, Route("rolelist")]
        public async Task<IActionResult> GetRoleList()
        {
            var result = await _sysRoleRepository.GetRoleList();
            return Ok(result);
        }
        /// <summary>
        /// 根据角色获取所有菜单
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        [HttpGet, Route("permissionlist/{roleid}")]
        public async Task<IActionResult> GetPermissionListAsync(long roleId)
        {
            var result = await _sysRoleRepository.GetPermissionListAsync(roleId);
            return Ok(result);
        }
        /// <summary>
        /// 添加或修改角色
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="permissions"></param>
        /// <returns></returns>
        [HttpPost,Route("addrolepermission")]
        public async Task<IActionResult> AddRolePermission(PermissionDto permissionDto)
        {
            var result = await _sysRoleRepository.AddRolePermission(permissionDto);
            return Ok(result);

        }
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        [HttpPost, Route("deleterole/{roleid}")]
        public async Task<IActionResult> DeleteRole(long roleId)
        {
            var result = await _sysRoleRepository.DeleteRole(roleId);
            return Ok(result);

        }
    }
}
